package system

import (
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"wave-admin/global"
	"wave-admin/model/common/response"
)

type AttachApi struct{}

// @Tags Attach
// @Summary 上传文件
// @Produce application/json
// @Param file path string true "文件"
// @Success 200 {string} json "{"code":200,"data":null,"msg":"上传成功！"}"
// @Router /api/v1/attach/upload [post]
func (a *AttachApi) Upload(ctx *gin.Context) {
	_, header, err1 := ctx.Request.FormFile("file")
	if err1 != nil {
		global.GnLog.Error("接收文件失败!", zap.Error(err1))
		response.FailWithMessage(ctx, "接收文件失败")
		return
	}
	urls, err := attachService.UploadFile(header)
	if err != nil {
		global.GnLog.Error("上传失败!", zap.Error(err))
		response.FailWithMessage(ctx, "上传失败" + err.Error())
	} else {
		response.Success(ctx, urls, "上传成功！")
	}
}